<template>
  <view>
    <mian-index ref="childer" @send="getSonValue"></mian-index>
    <button
      v-if="sonvalue.isVerified && sonvalue.isVerified == 1"
      @click="editor"
      class="arc_button btn_appointment"
    >
      实名认证
    </button>
    <button class="btn_appointment arc_button" type="default" @click="last">
      下一步
    </button>
  </view>
</template>

<script>
import { childer } from '@/pagesSub/components/ofPatient.vue'
import { undoneConsult } from '@/api/user.js'
import store from '@/store'
export default {
  components: {
    'mian-index': childer,
  },
  data() {
    return {
      consultType: 0,
      choosePeopleInfo: [],
      sonvalue: {},
	  doctorIdParam:0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      typeStatus: {
        1: '图文咨询',
        2: '用药咨询',
        3: '免费咨询',
      },
    }
  },
  onShow() {
    this.$refs.childer.patientListInfo()
    this.$refs.childer.peopleNumber()
    this.sonvalue = {}
  },
  onLoad: function (option) {
	this.doctorIdParam = option.doctorId ||0;
    if (option.type) {
      //问诊类型1付费问诊 2 免费义诊
      this.consultType = option.type
    } else {
      setTimeout(function () {
        uni.showToast({
          title: '您未选择问诊类型',
          icon: 'none',
          duration: 3000,
        })
      }, 2000)
      setTimeout(function () {
        uni.redirectTo({
          url: `/pages/homePage/doctorPage`,
        })
      }, 5000)
      return
    }
    // this.getOrderInfo();
  },
  methods: {
    getSonValue: function (res) {
      // console.log("子组件参数……………………",JSON.stringify(res))
      this.sonvalue = res
    },
    last() {
      // console.log("sonvalue……………………",JSON.stringify(this.sonvalue))
	  let _this = this;
	  let doctorId = 0;
	  if(_this.doctorIdParam>0){
		  doctorId = _this.doctorIdParam
	  }else{
		  doctorId = store.state.app.serviceUid
	  }
	  this.sonvalue.doctorId = doctorId;
	  // console.log('****************',this.sonvalue)
      if (this.sonvalue && this.sonvalue.isVerified == 0) {
        this.sonvalue.type = this.consultType
        let items = encodeURIComponent(JSON.stringify(this.sonvalue))
        console.log(this.sonvalue.patientId)
        undoneConsult(this.sonvalue.patientId, doctorId)
          .then((res) => {
            this.type = this.typeStatus[res.data.type]
            console.log(this.type)
            if (res.data.isExist == 0) {
              uni.showToast({
                title: '存在未完成的' + this.type,
                icon: 'none',
                duration: 3000,
              })
            } else {
              uni.redirectTo({
                url: `./consultation?item=${items}`,
              })
            }
          })
          .catch((err) => {
            console.log(err)
          })
        /*uni.redirectTo({
						url: `./consultation?item=${items}`
					})*/
      } else {
        uni.showToast({
          title: '请选择就诊人',
          icon: 'none',
          duration: 3000,
        })
      }
      if (this.sonvalue.isVerified == 1) {
        uni.showToast({
          title: '该就诊人未实名，请去实名',
          icon: 'none',
          duration: 3000,
        })
        return
      }
    },
    editor() {
      uni.navigateTo({
        url: `/pagesSub-My/my/editPatients?patientId=${this.sonvalue.patientId}`,
      })
    },
    choosePeople(data) {
      this.choosePeopleInfo = data
    },
  },
}
</script>

<style scoped>
.content {
  padding: 10rpx;
  display: flex;
  flex-wrap: wrap;
}
.content view {
  /* width: 150rpx; */
  margin-left: 10rpx;
  padding: 10rpx;
  background-color: #ffffff;
  border-radius: 10rpx;
  /* margin-right: 20rpx; */
  margin-bottom: 20rpx;
}
.introduce {
  font-size: 29rpx;
}
.introduce text {
  margin-right: 20rpx;
}
.btn_appointment {
  margin-top: 40rpx;
  background: -webkit-linear-gradient(#77e2a4, #4ccdbc);
  color: #ffffff;
}
</style>
